********************************************************************************
* Terrorism, perpetrators and polarization: Evidence from natural experiments 
* ONLINE APPENDIX 
* BY BOVE, DI LEO, EFTHYVOULOU & PICKARD
********************************************************************************

***Note for the replicator: Figure C.13a cannot be replicated as it employs proprietary data from Twitter, so we cannot share the data. 
*The data employed in the analysis can be downloaded from Twitter, using the API: https://developer.twitter.com/en/docs/twitter-api

*Creates folders
mkdir "Figures/Appendix C"

mkdir "Tables/Appendix B"
mkdir "Tables/Appendix C"


*set scheme for figures' style
set scheme hp

*clear preexisting data
clear all

*turn graphic elaboration off
set graphics off

*open the dataset
use "Polarization_clean.dta", clear


*Define controls
glo controls "age age2 female i.work_clean i.education_clean i.marital_clean i.children_clean i.ethnicity_clean i.religion_clean"



#########################
# APPENDIX B
#########################


********************************************************************************
*** TABLE B.1
********************************************************************************

capture noisily: erase "Tables/Appendix B/Table_B1_far_right.html"

*far right
est clear
foreach yyy in dista_labcon likecon likelab mii_terror immigecon immigcultural likeukip {
		
		cap drop s_attacks_*
		cap drop `yyy'_sample
		bys wave attack_id: egen p_c=sd(post) if `yyy'!=.
		gen s_attacks_`yyy'=(p_c>0 & p_c!=.)
		drop p_c
		
		qui cap reghdfe `yyy' post $controls if s_attacks_`yyy' & gname_small==2, absorb(oslauawave) vce(cluster oslaua)
		g `yyy'_sample=e(sample)
		
		cap n estpost sum `yyy' if `yyy'_sample==1
		
		esttab using "Tables/Appendix B/Table_B1_far_right", cells("mean(fmt(%8.2f)) sd(fmt(%8.2f)) min(fmt(%8.2f)) max(fmt(%8.2f)) count(fmt(%8.0f)) blank()") nonumbers noobs  wide ///
		collabels("Mean" "Std. Dev." "Min." "Max." "Obs." "Definition") ///
		varl(dista_labcon "Affective Polarization" likecon "Like Conservatives" likelab "Like Labour" mii_terror "Terrorism Most Important Issue" immigecon "Immigration Good for the Economy" immigcultural "Immigration Enriches Cultural Life"  likeukip "Like UKIP") ///	
		append html	
		
}

*islamic attacks
capture noisily: erase "Tables/Appendix B/Table_B1_islamic.html"

est clear
foreach yyy in dista_labcon likecon likelab mii_terror likeukip {
		
		cap drop s_attacks_*
		cap drop `yyy'_sample
		bys wave attack_id: egen p_c=sd(post) if `yyy'!=.
		gen s_attacks_`yyy'=(p_c>0 & p_c!=.)
		drop p_c
		
		qui cap reghdfe `yyy' post $controls if s_attacks_`yyy' & gname_small==3, absorb(oslauawave) vce(cluster oslaua)
		g `yyy'_sample=e(sample)
		
		cap n estpost sum `yyy' if `yyy'_sample==1
		
		esttab using "Tables/Appendix B/Table_B1_islamic", cells("mean(fmt(%8.2f)) sd(fmt(%8.2f)) min(fmt(%8.2f)) max(fmt(%8.2f)) count(fmt(%8.0f)) blank()") nonumbers noobs  wide ///
		collabels("Mean" "Std. Dev." "Min." "Max." "Obs." "Definition") ///
		varl(dista_labcon "Affective Polarization" likecon "Like Conservatives" likelab "Like Labour" mii_terror "Terrorism Most Important Issue" immigecon "Immigration Good for the Economy" immigcultural "Immigration Enriches Cultural Life"  likeukip "Like UKIP") ///	
		append html	
		
}





********************************************************************************
*** TABLE B.2
********************************************************************************

preserve

est clear

*keep respondents from waves/attacks where the question under scrutiny was asked
bys wave attack_id: egen p_c=sd(post) if dista_labcon!=.
gen s_attacks_dista_labcon=(p_c>0 & p_c!=.)
drop p_c

*create indicators for controls
ta work_clean, g(work_clean_)
ta education_clean, g(education_clean_)
ta marital_clean, g(marital_clean_)
ta children_clean, g(children_clean_)
ta ethnicity_clean, g(ethnicity_clean_)
ta religion_clean, g(religion_clean_)

*global with all controls as indicators
glo controls_sum "age age2 female work_clean_* education_clean_* marital_clean_* children_clean_* ethnicity_clean_* religion_clean_*"


*make sure the sample for which we calculate the histogram was interviewed around either an Islamic or Far-Right attack
qui reghdfe dista_labcon post $controls_sum if s_attacks_dista_labcon & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)
g farright_sample=e(sample)

qui reghdfe dista_labcon post $controls_sum if s_attacks_dista_labcon & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)
g islamic_sample=e(sample)


// Table

* far-right summary stats: controls
estpost sum $controls_sum if farright_sample==1

esttab using "Tables/Appendix B/Table_B2_far_right", cells("mean(fmt(%8.2f)) sd(fmt(%8.2f)) min(fmt(%8.2f)) max(fmt(%8.2f)) count(fmt(%8.0f))") nonumbers noobs  wide ///
collabels("Mean" "Std. Dev." "Min." "Max." "Obs.") ///
varl(female "Female" age "Age" age2 "Age sqr." work_clean_1 "Employed" work_clean_2 "Student/other" work_clean_3 "Retired" work_clean_4 "Unemployed/Not working" education_clean_1 "Educ.: Below GCSE" education_clean_2 "Educ.: GCSE/A-level/Diploma" education_clean_3 "Educ.: Bachelor or higher" marital_clean_1 "Single" marital_clean_2 "In a relationship" marital_clean_3 "Separated/Divorced/Widowed" ethnicity_clean_1 "Non white British" ethnicity_clean_2 "White British" children_clean_1 "No Children" children_clean_2 "1 or more child" religion_clean_1 "No religion" religion_clean_2 "Christian" religion_clean_3 "Islamic" religion_clean_4 "Other religion" _cons "Constant") ///	
replace html


* islamic attacks summmary stats: controls
estpost sum $controls_sum if islamic_sample==1

esttab using "Tables/Appendix B/Table_B2_islamic", cells("mean(fmt(%8.2f)) sd(fmt(%8.2f)) min(fmt(%8.2f)) max(fmt(%8.2f)) count(fmt(%8.0f)) blank()") nonumbers noobs  wide ///
collabels("Mean" "Std. Dev." "Min." "Max." "Obs." "Definition") ///
varl(female "Female" age "Age" age2 "Age sqr." work_clean_1 "Employed" work_clean_2 "Student/other" work_clean_3 "Retired" work_clean_4 "Unemployed/Not working" education_clean_1 "Educ.: Below GCSE" education_clean_2 "Educ.: GCSE/A-level/Diploma" education_clean_3 "Educ.: Bachelor or higher" marital_clean_1 "Single" marital_clean_2 "In a relationship" marital_clean_3 "Separated/Divorced/Widowed" ethnicity_clean_1 "Non white British" ethnicity_clean_2 "White British" children_clean_1 "No Children" children_clean_2 "1 or more child" religion_clean_1 "No religion" religion_clean_2 "Christian" religion_clean_3 "Islamic" religion_clean_4 "Other religion" _cons "Constant") ///	
replace html

restore





********************************************************************************
*** TABLE B.3
********************************************************************************

preserve

est clear

*keep respondents from waves/attacks where the question under scrutiny was asked
bys wave attack_id: egen p_c=sd(post) if dista_labcon!=.
gen s_attacks_dista_labcon=(p_c>0 & p_c!=.)
drop p_c

*create indicators for controls
ta work_clean, g(work_clean_)
ta education_clean, g(education_clean_)
ta marital_clean, g(marital_clean_)
ta children_clean, g(children_clean_)
ta ethnicity_clean, g(ethnicity_clean_)
ta religion_clean, g(religion_clean_)
glo controls_sum "age age2 female work_clean_* education_clean_* marital_clean_* children_clean_* ethnicity_clean_* religion_clean_*"

*make sure the sample for which we calculate the histogram was interviewed around either an Islamic or Far-Right attack
qui reghdfe dista_labcon post $controls if s_attacks_dista_labcon & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)
g farright_sample=e(sample)

qui reghdfe dista_labcon post $controls if s_attacks_dista_labcon & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)
g islamic_sample=e(sample)

* differences pre-post
eststo pre_farright: estpost summarize $controls_sum if post == 0 & farright_sample == 1
eststo post_farright: estpost summarize $controls_sum if post == 1 & farright_sample == 1
eststo diff_farright: estpost ttest $controls_sum if farright_sample == 1, by(post)    

eststo pre_islamic: estpost summarize $controls_sum if post == 0 & islamic_sample == 1
eststo post_islamic: estpost summarize $controls_sum if post == 1 & islamic_sample == 1
eststo diff_islamic: estpost ttest $controls_sum if islamic_sample == 1, by(post)    


esttab pre_farright post_farright diff_farright pre_islamic post_islamic diff_islamic ///
using "Tables/Appendix B/Table_B3", ///
mtitles("Mean (control)" "Mean (treatment)" "Diff." "Mean (control)" "Mean (treatment)" "Diff." ) ///
cells("mean(pattern(1 1 0 1 1 0) fmt(2))  b(pattern(0 0 1 0 0 1) fmt(2)) p(pattern(0 0 1 0 0 1) fmt(2))") ///
varl(female "Female" age "Age" age2 "Age sqr." work_clean_1 "Employed" work_clean_2 "Student/other" work_clean_3 "Retired" work_clean_4 "Unemployed/Not working" education_clean_1 "Educ.: Below GCSE" education_clean_2 "Educ.: GCSE/A-level/Diploma" education_clean_3 "Educ.: Bachelor or higher" marital_clean_1 "Single" marital_clean_2 "In a relationship" marital_clean_3 "Separated/Divorced/Widowed" ethnicity_clean_1 "Non white British" ethnicity_clean_2 "White British" children_clean_1 "No Children" children_clean_2 "1 or more child" religion_clean_1 "No religion" religion_clean_2 "Christian" religion_clean_3 "Islamic" religion_clean_4 "Other religion" _cons "Constant") ///	
stats(N, label("Observations")) ///
replace html 

restore



#########################
# APPENDIX C
#########################

********************************************************************************
*** Table C.1a
********************************************************************************

cap drop s_attacks_*

*NOTE HERE we condition on (a) lag_dista_labcon BEING NON-MISSING and (b) all the controls being there
**** 

*keep respondents 
bys wave attack_id: egen post_sd=sd(post) if lag_dista_labcon!=. & age!=. & age2!=. & female!=. & work_clean!=. & education_clean!=. & marital_clean!=. & children_clean!=. & ethnicity_clean!=. & religion_clean!=. 
gen s_attacks_dista_labcon=(post_sd>0 & post_sd!=.)
drop post_sd

// Table 
est clear
*AGG. baseline
capture noisily eststo: reghdfe dista_labcon post if s_attacks_dista_labcon, absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc controls "No", replace

*AGG. controls
capture noisily eststo: reghdfe dista_labcon post $controls if s_attacks_dista_labcon, absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc controls "Yes", replace

*AGG. lag 
capture noisily eststo: reghdfe dista_labcon post $controls lag_dista_labcon if s_attacks_dista_labcon, absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc controls "Yes", replace

*FAR-RIGHT baseline
capture noisily eststo: reghdfe dista_labcon post if s_attacks_dista_labcon & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc rightwing "Yes", replace
		estadd loc jihadi "No", replace
		estadd loc controls "No", replace

*FAR-RIGHT controls
capture noisily eststo: reghdfe dista_labcon post $controls if s_attacks_dista_labcon & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc rightwing "Yes", replace
		estadd loc jihadi "No", replace
		estadd loc controls "Yes", replace

*FAR-RIGHT lag 
capture noisily eststo: reghdfe dista_labcon post $controls lag_dista_labcon if s_attacks_dista_labcon & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc rightwing "Yes", replace
		estadd loc jihadi "No", replace
		estadd loc controls "Yes", replace

*ISLAMIC baseline
capture noisily eststo: reghdfe dista_labcon post if s_attacks_dista_labcon & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc rightwing "No", replace
		estadd loc jihadi "Yes", replace
		estadd loc controls "No", replace

*ISLAMIC controls
capture noisily eststo: reghdfe dista_labcon post $controls if s_attacks_dista_labcon & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc rightwing "No", replace
		estadd loc jihadi "Yes", replace
		estadd loc controls "Yes", replace
		
*ISLAMIC lag 
capture noisily eststo: reghdfe dista_labcon post $controls lag_dista_labcon if s_attacks_dista_labcon & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc rightwing "No", replace
		estadd loc jihadi "Yes", replace
		estadd loc controls "Yes", replace
		
esttab est* using "Tables/Appendix C/Table_C1a", star(* .1 ** .05 *** .01) se b(3) r2 ///
keep(post lag_dista_labcon) ///
order(post lag_dista_labcon) ///
varl(post "Post-attack" lag_dista_labcon "Lagged Affective Polarisation") ///
s(rightwing jihadi oslauawave controls N_clust r2 N, ///
label("Far-right attacks" "Islamic attacks" "LAD $\times$ Wave FEs" "Controls" "No. of LADs" "R-squared" "Observations") ///
fmt(3 3 3 3 %9.0f 3 %9.0f)) ///
replace html nonotes	 




********************************************************************************
*** Table C.1b
********************************************************************************

cap drop s_attacks_*

*keep respondents from waves/attacks where the question under scrutiny was asked
bys wave attack_id: egen post_sd=sd(post) if dista_labcon!=.
gen s_attacks_dista_labcon=(post_sd>0 & post_sd!=.)
drop post_sd

// table 

est clear 
*AGG. baseline
capture noisily eststo: reghdfe dista_labcon i.post##i.islamic if s_attacks_dista_labcon, absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc controls "No", replace

*AGG. controls
capture noisily eststo: reghdfe dista_labcon i.post##i.islamic  $controls if s_attacks_dista_labcon, absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc controls "Yes", replace

*AGG. lag 
capture noisily eststo: reghdfe dista_labcon i.post##i.islamic  $controls lag_dista_labcon if s_attacks_dista_labcon, absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc controls "Yes", replace


esttab est* using "Tables/Appendix C/Table_C1b", star(* .1 ** .05 *** .01) se b(3) r2 ///
keep(1.post 1.post#1.islamic lag_dista_labcon) ///
order(1.post 1.post#1.islamic lag_dista_labcon) ///
varl(1.post "Post-attack" 1.post#1.islamic "Post-attack $\times$ Islamic Attacks" lag_dista_labcon "Lagged Affective Polarisation") ///
s(oslauawave controls N_clust r2 N, ///
label("LAD $\times$ Wave FEs" "Controls" "No. of LADs" "R-squared" "Observations") ///
fmt(3 3 %9.0f 3 %9.0f)) ///
replace html nonotes	


// add margins
est clear
*AGG. baseline
qui reghdfe dista_labcon i.post##i.islamic if s_attacks_dista_labcon, absorb(oslauawave, save) vce(cluster oslaua)
eststo: margins islamic, dydx(post) noestimcheck post

*AGG. controls
qui reghdfe dista_labcon i.post##i.islamic  $controls if s_attacks_dista_labcon, absorb(oslauawave, save) vce(cluster oslaua)
eststo: margins islamic, dydx(post) noestimcheck post

*AGG. lag 
qui reghdfe dista_labcon i.post##i.islamic  $controls lag_dista_labcon if s_attacks_dista_labcon, absorb(oslauawave, save) vce(cluster oslaua)
eststo: margins islamic, dydx(post) noestimcheck post

esttab est* using "Tables/Appendix C/Table_C1b", star(* .1 ** .05 *** .01) se b(3) r2 ///
keep(0.islamic 1.islamic) ///
order(0.islamic 1.islamic) ///
varl(0.islamic "Post-attack for Non-Islamic Attacks" 1.islamic "Post-attack for Islamic attacks") ///
s(oslauawave controls N_clust r2 N, ///
label("LAD $\times$ Wave FEs" "Controls" "No. of LADs" "R-squared" "Observations") ///
fmt(3 3 %9.0f 3 %9.0f)) ///
append html nonotes	





********************************************************************************
*** FIGURE C.2a
********************************************************************************

*lifted from Boxell, Gentzkow and Shapiro (2022) Figure 1 and Figure 2





********************************************************************************
*** FIGURE C.2b
********************************************************************************

***see construction of the index in the dataclean do 

cap drop s_attacks_* 

foreach y in wgt_spread {

	*keep respondents from waves/attacks where the question under scrutiny was asked
	bys wave attack_id: egen p_c=sd(post) if `y'!=.
	gen s_attacks_`y'=(p_c>0 & p_c!=.)
	drop p_c

	est clear

	*FAR-RIGHT
	*controls 
	capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n1=e(N)
	*no controls 
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)

	*ISLAMIC
	*controls 
	capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n2=e(N)
	*no controls 
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)

	*FAR-RIGHT (ENGLAND ONLY)
	*controls 
	capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & gname_small==2 & region!=10 & region!=11 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n1_engl=e(N)
	*no controls
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & gname_small==2 & region!=10 & region!=11 , absorb(oslauawave, save) vce(cluster oslaua)

	*ISLAMIC (ENGLAND ONLY)
	*controls 
	capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & gname_small==3 & region!=10 & region!=11 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n2_engl=e(N)
	*no controls 
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & gname_small==3 & region!=10 & region!=11 , absorb(oslauawave, save) vce(cluster oslaua)

	coefplot ///
	(est1, offset(0.2)  keep(post) rename(post = "Far-right Attacks") label(2 days) msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est2, offset(-0.2) keep(post) rename(post = "Far-right Attacks") label(3 days) msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est3, offset(0.2)  keep(post) rename(post = "Islamic Attacks") label(2 days) msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est4, offset(-0.2) keep(post) rename(post = "Islamic Attacks") label(3 days) msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est5, offset(0.2)  keep(post) rename(post = "Far-right Attacks (England)") label(2 days) msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est6, offset(-0.2) keep(post) rename(post = "Far-right Attacks (England)") label(3 days) msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est7, offset(0.2)  keep(post) rename(post = "Islamic Attacks (England)") label(2 days) msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est8, offset(-0.2) keep(post) rename(post = "Islamic Attacks (England)") label(3 days) msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	, levels(95 90) ///
	xtitle("Coefficient of 'Post-attack'") ///
	groups("Far-right Attacks" = "N = `n1'" "Islamic Attacks" = "N = `n2'" "Far-right Attacks (England)" = "N = `n1_engl'" "Islamic Attacks (England)" = "N = `n2_engl'") ///
	yscale(alt axis(2)) ///
	xlabel(-0.4(0.2)0.4) ///
	grid(between glpattern(dash) glwidth(*2) glcolor(white) nogextend) ///
	plotregion(lc(black)) ///
	xline(0, lc(red) lp(dash)) ///
	yline(4, lc(gs12%60) lp(solid) lw(medthick)) ///
	legend(order(3 "Controls" 6 "No Controls") pos(6) row(1))
	
	gr export "Figures/Appendix C/Figure_C2b.png", width(4000) replace

	}	


	
	

********************************************************************************
*** FIGURE C.2c
********************************************************************************

cap drop s_attacks_*

foreach y in dista_leftright {

	*keep respondents from waves/attacks where the question under scrutiny was asked
	bys wave attack_id: egen p_c=sd(post) if `y'!=.
	gen s_attacks_`y'=(p_c>0 & p_c!=.)
	drop p_c

	est clear
	
	*FAR-RIGHT
	*controls 
	capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n1=e(N)
	*no controls 
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)

	*ISLAMIC
	*controls 
	capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n2=e(N)
	*no controls 
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)

	*FAR-RIGHT (ENGLAND ONLY)
	*controls 
	capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & gname_small==2 & region!=10 & region!=11 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n1_engl=e(N)
	*no controls 
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & gname_small==2 & region!=10 & region!=11 , absorb(oslauawave, save) vce(cluster oslaua)

	*ISLAMIC (ENGLAND ONLY)
	*controls 
	capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & gname_small==3 & region!=10 & region!=11 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n2_engl=e(N)
	*no controls 
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & gname_small==3 & region!=10 & region!=11 , absorb(oslauawave, save) vce(cluster oslaua)

	coefplot ///
	(est1, offset(0.2)  keep(post) rename(post = "Far-right Attacks") label(2 days) msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est2, offset(-0.2) keep(post) rename(post = "Far-right Attacks") label(3 days) msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est3, offset(0.2)  keep(post) rename(post = "Islamic Attacks") label(2 days) msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est4, offset(-0.2) keep(post) rename(post = "Islamic Attacks") label(3 days) msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est5, offset(0.2)  keep(post) rename(post = "Far-right Attacks (England)") label(2 days) msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est6, offset(-0.2) keep(post) rename(post = "Far-right Attacks (England)") label(3 days) msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est7, offset(0.2)  keep(post) rename(post = "Islamic Attacks (England)") label(2 days) msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est8, offset(-0.2) keep(post) rename(post = "Islamic Attacks (England)") label(3 days) msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	, levels(95 90) ///
	xtitle("Coefficient of 'Post-attack'") ///
	groups("Far-right Attacks" = "N = `n1'" "Islamic Attacks" = "N = `n2'" "Far-right Attacks (England)" = "N = `n1_engl'" "Islamic Attacks (England)" = "N = `n2_engl'") ///
	yscale(alt axis(2)) ///
	xlabel(-0.4(0.2)0.4) ///
	grid(between glpattern(dash) glwidth(*2) glcolor(white) nogextend) ///
	plotregion(lc(black)) ///
	xline(0, lc(red) lp(dash)) ///
	yline(4, lc(gs12%60) lp(solid) lw(medthick)) ///
	legend(order(3 "Controls" 6 "No Controls") pos(6) row(1))
	
	gr export "Figures/Appendix C/Figure_C2c.png", width(4000) replace

	}	




********************************************************************************
*** FIGURE C.3
********************************************************************************

qui { // FIGURE

est clear

cap drop s_attacks_*

*keep respondents from waves/attacks where the question under scrutiny was asked
bys wave attack_id: egen post_sd=sd(post) if dista_labcon!=.
gen s_attacks_dista_labcon=(post_sd>0 & post_sd!=.)
drop post_sd

loc n=0
forv i=2/3 {
	
	loc ++n

	* imputed lag
	eststo: reghdfe dista_labcon post $controls if s_attacks_dista_labcon & gname_small==`i' & (lag_partyid_imp_lab==1 | lag_partyid_imp_con==1 | lag_partyid_imp_greenlib==1) , absorb(oslauawave) vce(cluster oslaua)
	eststo: reghdfe dista_labcon post if s_attacks_dista_labcon & gname_small==`i' & (lag_partyid_imp_lab==1 | lag_partyid_imp_con==1 | lag_partyid_imp_greenlib==1) , absorb(oslauawave) vce(cluster oslaua)
	loc n`n'=e(N)
	loc ++n
	
	* last 2 waves
	eststo: reghdfe dista_labcon post $controls if s_attacks_dista_labcon & gname_small==`i' & (ever_2w_party_lab==1 | ever_2w_party_con==1 | ever_2w_party_greenlib==1) , absorb(oslauawave) vce(cluster oslaua)
	eststo: reghdfe dista_labcon post if s_attacks_dista_labcon & gname_small==`i' & (ever_2w_party_lab==1 | ever_2w_party_con==1 | ever_2w_party_greenlib==1) , absorb(oslauawave) vce(cluster oslaua)
	loc n`n'=e(N)
	loc ++n

	* last 3 waves
	eststo: reghdfe dista_labcon post $controls if s_attacks_dista_labcon & gname_small==`i' & (ever_3w_party_lab==1 | ever_3w_party_con==1 | ever_3w_party_greenlib==1) , absorb(oslauawave) vce(cluster oslaua)
	eststo: reghdfe dista_labcon post if s_attacks_dista_labcon & gname_small==`i' & (ever_3w_party_lab==1 | ever_3w_party_con==1 | ever_3w_party_greenlib==1) , absorb(oslauawave) vce(cluster oslaua)
	loc n`n'=e(N)

}


coefplot ///
(est1, offset(0.2)   keep(post) rename(post = "Partisan identity") msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
(est2, offset(-0.2)  keep(post) rename(post = "Partisan identity") msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
(est3, offset(0.2)   keep(post) rename(post = "Constant partisan identity (2 waves)") msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
(est4, offset(-0.2)  keep(post) rename(post = "Constant partisan identity (2 waves)") msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
(est5, offset(0.2)   keep(post) rename(post = "Constant partisan identity (3 waves)") msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
(est6, offset(-0.2)  keep(post) rename(post = "Constant partisan identity (3 waves)") msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
(est7, offset(0.2)   keep(post) rename(post = " Partisan identity") msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
(est8, offset(-0.2)  keep(post) rename(post = " Partisan identity") msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
(est9, offset(0.2)   keep(post) rename(post = " Constant partisan identity (2 waves)") msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
(est10, offset(-0.2)  keep(post) rename(post = " Constant partisan identity (2 waves)") msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
(est11, offset(0.2)   keep(post) rename(post = " Constant partisan identity (3 waves)") msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
(est12, offset(-0.2)  keep(post) rename(post = " Constant partisan identity (3 waves)") msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
, levels(95 90) ///
xtitle("Coefficient of 'Post-attack'") ///	
groups("Partisan identity"="N = `n1'" "Constant partisan identity (2 waves)"="N = `n2'" "Constant partisan identity (3 waves)"="N = `n3'" " Partisan identity"="N = `n4'" " Constant partisan identity (2 waves)"="N = `n5'" " Constant partisan identity (3 waves)"="N = `n6'") ///
headings("Partisan identity" = "{bf:Far-right Attacks}" " Partisan identity" = "{bf:Islamic Attacks}") ///
yscale(alt axis(2)) ///
xlabel(-0.4(0.2)0.4) ///
grid(between glpattern(dash) glwidth(*2) glcolor(white) nogextend) ///
plotregion(lc(black)) ///
xline(0, lc(red) lp(dash)) ///
yline(8, lc(gs12%60) lp(solid) lw(medthick)) ///
legend(order(3 "Controls" 6 "No Controls") pos(6) row(1))
	
gr export "Figures/Appendix C/Figure_C3.png", width(4000) replace
	
}







********************************************************************************
*** FIGURE C.4
********************************************************************************

cap drop s_attacks_* 
	
*FAR-RIGHT ATTACKS

est clear	
loc i=1
forv h=0(7)14 {

	*create placebo attack 
	g post_pl_`i'=(time_dist>=-8-`h')
	replace post_pl_`i'=. if time_dist<-15-`h' | time_dist>-1-`h'
	replace post_pl_`i'=. if time_dist==-8-`h'
	*ta post_pl_`i'=.
	
	ta time_dist post_pl_`i'
	*drop post_pl_`i'
		
	*keep respondents from waves/attacks where the question under scrutiny was asked
	bys wave attack_id: egen p_c=sd(post_pl_`i') if dista_labcon!=.
	g s_attacks_dista_labcon=(p_c>0 & p_c!=.)
	
	*no controls
	eststo: reghdfe dista_labcon post_pl_`i' if s_attacks_dista_labcon & gname_small==2 , absorb(oslauawave) vce(cluster oslaua)
	*controls
	eststo: reghdfe dista_labcon post_pl_`i' $controls if s_attacks_dista_labcon & gname_small==2, absorb(oslauawave) vce(cluster oslaua)
	
	drop p_c s_attacks_dista_labcon post_pl_`i'
	
	loc i=`i'+1
	
	}

coefplot ///
(est6, offset(-0.1)  keep(post_pl_3) rename(post_pl_3 = "-22") msymbol(circle)  mcolor(black)) ///
(est5, offset(0.1)  keep(post_pl_3) rename(post_pl_3 = "-22") msymbol(X) msize(large) mcolor(black)) ///
(est4, offset(-0.1)  keep(post_pl_2) rename(post_pl_2 = "-15") msymbol(circle)  mcolor(black)) ///
(est3, offset(0.1)  keep(post_pl_2) rename(post_pl_2 = "-15") msymbol(X) msize(large) mcolor(black)) ///
(est2, offset(-0.1)  keep(post_pl_1) rename(post_pl_1 = "-8")  msymbol(circle)  mcolor(black)) ///
(est1, offset(0.1)  keep(post_pl_1) rename(post_pl_1 = "-8")  msymbol(X) msize(large) mcolor(black)) ///
, levels(95 90) vert ///
yline(0) ///
ciopts(lcolor(black black)) ///
ytitle("") xtitle("") title("Far-right attacks") ///
plotregion(lc(black)) ///
ylabel(-0.4(0.1)0.4) ///
xscale(range(1 5.3)) xline(3.2, lc(black)) xline(4.2, lc(black) lp(solid)) xline(5.2, lc(black)) ///
addplot( ///
(scatteri .4 4.2 -.4 4.2 -.4 3.2 .4 3.2, fcolor(blue%30) lc(black%10) recast(area)) ///
(scatteri .4 4.2 .4 4.2 .4 3.2 .4 3.2, fcolor(blue%30) lc(black%10) recast(area)) ///
(scatteri .4 5.2 -.4 5.2 -.4 4.2 .4 4.2, fcolor(red%50) lc(black%10) recast(area)) ///
(scatteri .4 5.2 .4 5.2 .4 4.2 .4 4.2, fcolor(red%50) lc(black%10) recast(area)) ///
) ///
name("gr_1", replace)

	
*ISLAMIC ATTACKS
est clear
loc i=1
forv h=0(7)14 {

	*create placebo attack 
	g post_pl_`i'=(time_dist>=-8-`h')
	replace post_pl_`i'=. if time_dist<-15-`h' | time_dist>-1-`h'
	replace post_pl_`i'=. if time_dist==-8-`h'
	*ta post_pl_`i'=.
	
	ta time_dist post_pl_`i'
	*drop post_pl_`i'
		
	*keep respondents from waves/attacks where the question under scrutiny was asked
	bys wave attack_id: egen p_c=sd(post_pl_`i') if dista_labcon!=.
	g s_attacks_dista_labcon=(p_c>0 & p_c!=.)
	
	*no controls
	eststo: reghdfe dista_labcon post_pl_`i' if s_attacks_dista_labcon & gname_small==3, absorb(oslauawave) vce(cluster oslaua)
	*controls 
	eststo: reghdfe dista_labcon post_pl_`i' $controls if s_attacks_dista_labcon & gname_small==3, absorb(oslauawave) vce(cluster oslaua)
	
	drop p_c s_attacks_dista_labcon post_pl_`i'
	
	loc i=`i'+1
	
	}

coefplot ///
(est6, offset(-0.1)  keep(post_pl_3) rename(post_pl_3 = "-22") msymbol(circle)  mcolor(black)) ///
(est6, offset(-0.1)  keep(post_pl_3) rename(post_pl_3 = "-22") msymbol(circle)  mcolor(black)) ///
(est5, offset(0.1)   keep(post_pl_3) rename(post_pl_3 = "-22") msymbol(X) msize(large) mcolor(black)) ///
(est4, offset(-0.1)  keep(post_pl_2) rename(post_pl_2 = "-15") msymbol(circle)  mcolor(black)) ///
(est3, offset(0.1)   keep(post_pl_2) rename(post_pl_2 = "-15") msymbol(X) msize(large) mcolor(black)) ///
(est2, offset(-0.1)  keep(post_pl_1) rename(post_pl_1 = "-8")  msymbol(circle)  mcolor(black)) ///
(est1, offset(0.1)   keep(post_pl_1) rename(post_pl_1 = "-8")  msymbol(X) msize(large) mcolor(black)) ///
, levels(95 90) vert ///
yline(0) ///
ciopts(lcolor(black black)) ///
ytitle("") xtitle("") title("Islamic attacks") ///
legend(order(12 "Controls" 15 "No controls" 23 "Control group" 25 "Treatment group")) ///
plotregion(lc(black)) ///
ylabel(-0.4(0.1)0.4) ///
xscale(range(1 5.3)) xline(3.2, lc(black)) xline(4.2, lc(black) lp(solid)) xline(5.2, lc(black)) ///
addplot( ///
(scatteri .4 4.2 -.4 4.2 -.4 3.2 .4 3.2, fcolor(blue%30) lc(black%10) recast(area)) ///
(scatteri .4 4.2 .4 4.2 .4 3.2 .4 3.2, fcolor(blue%30) lc(black%10) recast(area)) ///
(scatteri .4 5.2 -.4 5.2 -.4 4.2 .4 4.2, fcolor(red%50) lc(black%10) recast(area)) ///
(scatteri .4 5.2 .4 5.2 .4 4.2 .4 4.2, fcolor(red%50) lc(black%10) recast(area)) ///
) ///
name("gr_2", replace)
	
	
grc1leg gr_1 gr_2 , ring(4) row(2) l1("Coefficient of 'Placebo Post-attack'") b1("Days relative to attack") legendfrom(gr_2)
gr export "Figures/Appendix C/Figure_C4.png", width(4000) replace





********************************************************************************
*** FIGURE C.5
********************************************************************************

cap drop s_attacks_* 

foreach y in dista_labcon {

	*keep respondents from waves/attacks where the question under scrutiny was asked
	bys wave attack_id: egen p_c=sd(post) if `y'!=.
	gen s_attacks_`y'=(p_c>0 & p_c!=.)
	drop p_c

	est clear
		
	*ALL ATTACKS
	capture noisily eststo: reghdfe `y'  post_3days if s_attacks_`y' , absorb(oslauawave, save) vce(cluster oslaua)
		loc beta=_b[post]
	
	*FAR-RIGHT
	capture noisily eststo: reghdfe `y'  post_3days $controls if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n1=e(N)
	capture noisily eststo: reghdfe `y'  post_3days if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)

	*ISLAMIC
	capture noisily eststo: reghdfe `y'  post_3days $controls if s_attacks_`y' & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n2=e(N)
	capture noisily eststo: reghdfe `y'  post_3days if s_attacks_`y' & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)

	coefplot ///
	(est2, offset(0.1)  keep(post_3days) rename(post_3days = "Far-right Attacks") label(2 days) msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est3, offset(-0.1) keep(post_3days) rename(post_3days = "Far-right Attacks") label(3 days) msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est4, offset(0.1)  keep(post_3days) rename(post_3days = "Islamic Attacks") label(2 days) msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est5, offset(-0.1) keep(post_3days) rename(post_3days = "Islamic Attacks") label(3 days) msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	, levels(95 90) ///
	xtitle("Coefficient of 'Post-attack'") ///
	groups("Far-right Attacks" = "N = `n1'" "Islamic Attacks" = "N = `n2'") ///
	yscale(alt axis(2)) ///
	xlabel(-0.4(0.2)0.4) ///
	grid(between glpattern(dash) glwidth(*2) glcolor(white) nogextend) ///
	plotregion(lc(black)) ///
	xline(0, lc(red) lp(dash)) ///
	yline(6, lc(gs12%60) lp(solid) lw(medthick)) ///
	legend(order(3 "Controls" 6 "No Controls") pos(6) row(1))
	
	gr export "Figures/Appendix C/Figure_C5.png", width(4000) replace
	
}	



	
	
********************************************************************************
*** FIGURE C.6
********************************************************************************

cap drop s_attacks_* 

foreach y in dista_labcon {

	*keep respondents from waves/attacks where the question under scrutiny was asked
	bys wave attack_id: egen p_c=sd(post) if `y'!=.
	gen s_attacks_`y'=(p_c>0 & p_c!=.)
	drop p_c

	est clear

	*1.  Define controls to balance on
	loc controls "age age2 female i.work_clean i.education_clean i.marital_clean i.children_clean i.ethnicity_clean i.religion_clean"

	*2 Locate the sample for the treatment (by type of attack)
	*3 entropy balance on the treatment sample (by type of attack)
	*4 save entropy weights (by type of attack)
	qui reghdfe `y' post $controls if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)
		g post_sample_right=e(sample)
		ebalance post `controls' if post_sample_right, tar(3) 
		rename _webal _webal_post_right

	qui reghdfe `y' post $controls if s_attacks_`y' & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)
		g post_sample_islamic=e(sample)
		ebalance post `controls' if post_sample_islamic, tar(3) 
		rename _webal _webal_post_islamic

	*5 regress using entropy weights

	*FAR-RIGHT
	capture noisily eststo: reghdfe `y'  post $controls [aw=_webal_post_right] if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n1=e(N)
	capture noisily eststo: reghdfe `y'  post [aw=_webal_post_right] if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)

	*ISLAMIC
	capture noisily eststo: reghdfe `y'  post $controls [aw=_webal_post_islamic] if s_attacks_`y' & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n2=e(N)
	capture noisily eststo: reghdfe `y'  post [aw=_webal_post_islamic] if s_attacks_`y' & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)
	
	coefplot ///
	(est1, offset(0.2)  keep(post) rename(post = "Far-right Attacks") label(2 days) msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est2, offset(-0.2) keep(post) rename(post = "Far-right Attacks") label(3 days) msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est3, offset(0.2)  keep(post) rename(post = "Islamic Attacks") label(2 days) msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est4, offset(-0.2) keep(post) rename(post = "Islamic Attacks") label(3 days) msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	, levels(95 90) ///
	xtitle("Coefficient of 'Post-attack'") ///
	groups("Far-right Attacks" = "N = `n1'" "Islamic Attacks" = "N = `n2'") ///
	yscale(alt axis(2)) ///
	xlabel(-0.4(0.2)0.4) ///
	grid(between glpattern(dash) glwidth(*2) glcolor(white) nogextend) ///
	plotregion(lc(black)) ///
	xline(0, lc(red) lp(dash)) ///
	legend(order(3 "Controls" 6 "No Controls") pos(6) row(1))	

	gr export "Figures/Appendix C/Figure_C6.png", width(4000) replace

}	




********************************************************************************
*** FIGURE C.7
********************************************************************************

cap drop s_attacks_* 

foreach y in dista_labcon {

	*keep respondents from waves/attacks where the question under scrutiny was asked
	bys wave attack_id: egen p_c=sd(post) if `y'!=.
	gen s_attacks_`y'=(p_c>0 & p_c!=.)
	drop p_c
	
	est clear
			
	** Baseline far right
	capture noisily eststo: reghdfe `y' post $controls if s_attacks_`y'  & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)
	loc beta=_b[post]
				
	** Drop region-by-region far right
	forv i=1/11 {
		capture noisily eststo: reghdfe `y' post $controls if s_attacks_`y' & region!=`i' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)
		}	

	coefplot ///                
    (est1,   offset(0)   keep(post) rename(post = "None")     msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
    (est2,   offset(0)   keep(post) rename(post = "N-E")      msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
    (est3,   offset(0)   keep(post) rename(post = "N-W")      msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
    (est4,   offset(0)   keep(post) rename(post = "York/Hum") msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
    (est5,   offset(0)   keep(post) rename(post = "E-Midl.")  msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
    (est6,   offset(0)   keep(post) rename(post = "W-Midl.")  msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
    (est7,   offset(0)   keep(post) rename(post = "E-Engl.")  msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
    (est8,   offset(0)   keep(post) rename(post = "London")   msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
    (est9,   offset(0)   keep(post) rename(post = "S-E")      msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
    (est10,  offset(0)   keep(post) rename(post = "S-W")      msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
    (est11,  offset(0)   keep(post) rename(post = "Wales")    msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
    (est12,  offset(0)   keep(post) rename(post = "Scotland") msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
    , levels(95 90) vert ////
	title("Far-right Attacks") ///
	yline(0, lc(red) lp(dash)) ///
	plotregion(lc(black)) ///
	ylabel(-0.4(0.2)0.4, nogrid nogextend) ///
	legend(off) name("Figure_C7_`y'_right", replace)
	
	}

	
***ISLAMIC
drop s_attacks_* 

foreach y in dista_labcon {

	*keep respondents from waves/attacks where the question under scrutiny was asked
	bys wave attack_id: egen p_c=sd(post) if `y'!=.
	gen s_attacks_`y'=(p_c>0 & p_c!=.)
	drop p_c
		
	est clear	
		
	** Baseline spec. islamic
	capture noisily eststo: reghdfe `y' post $controls if s_attacks_`y'  & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)
	loc beta=_b[post]
				
	** Drop region-by-region islamic
	forv i=1/11 {
		capture noisily eststo: reghdfe `y' post $controls if s_attacks_`y' & region!=`i' & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)
		}
		
	coefplot ///                
    (est1,   offset(0)   keep(post) rename(post = "None")     msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
    (est2,   offset(0)   keep(post) rename(post = "N-E")      msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
    (est3,   offset(0)   keep(post) rename(post = "N-W")      msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
    (est4,   offset(0)   keep(post) rename(post = "York/Hum") msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
    (est5,   offset(0)   keep(post) rename(post = "E-Midl.")  msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
    (est6,   offset(0)   keep(post) rename(post = "W-Midl.")  msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
    (est7,   offset(0)   keep(post) rename(post = "E-Engl.")  msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
    (est8,   offset(0)   keep(post) rename(post = "London")   msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
    (est9,   offset(0)   keep(post) rename(post = "S-E")      msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
    (est10,  offset(0)   keep(post) rename(post = "S-W")      msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
    (est11,  offset(0)   keep(post) rename(post = "Wales")    msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
    (est12,  offset(0)   keep(post) rename(post = "Scotland") msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
    , levels(95 90) vert ////
	title("Islamic Attacks") ///
	yline(0, lc(red) lp(dash)) ///
	plotregion(lc(black)) ///
	ylabel(-0.4(0.2)0.4, nogrid nogextend) ///
	legend(off) name("Figure_C7_`y'_islamic", replace)

	}

gr combine Figure_C7_dista_labcon_right Figure_C7_dista_labcon_islamic, ///
ycommon rows(2) l1("Coefficient of 'Post-attack'")

gr export "Figures/Appendix C/Figure_C7.png", width(4000) replace





********************************************************************************
*** FIGURE C.8
********************************************************************************

cap drop s_attacks_* 

foreach y in dista_labcon {

	*keep respondents from waves/attacks where the question under scrutiny was asked
	bys wave attack_id: egen p_c=sd(post) if `y'!=.
	gen s_attacks_`y'=(p_c>0 & p_c!=.)
	drop p_c

	est clear
	
	*ALL ATTACKS
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' , absorb(oslauawave, save) vce(cluster oslauawave)
		loc beta=_b[post]

	*FAR-RIGHT
	capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslauawave)
	loc n1=e(N)
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslauawave)

	*ISLAMIC
	capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & gname_small==3 , absorb(oslauawave, save) vce(cluster oslauawave)
	loc n2=e(N)
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & gname_small==3 , absorb(oslauawave, save) vce(cluster oslauawave)

	coefplot ///
	(est2, offset(0.2)  keep(post) rename(post = "Far-right Attacks") label(2 days) msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est3, offset(-0.2) keep(post) rename(post = "Far-right Attacks") label(3 days) msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est4, offset(0.2)  keep(post) rename(post = "Islamic Attacks") label(2 days) msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est5, offset(-0.2) keep(post) rename(post = "Islamic Attacks") label(3 days) msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	, levels(95 90) ///
	xtitle("Coefficient of 'Post-attack'") ///
	groups("Far-right Attacks" = "N = `n1'" "Islamic Attacks" = "N = `n2'") ///
	yscale(alt axis(2)) ///
	xlabel(-0.4(0.2)0.4) ///
	grid(between glpattern(dash) glwidth(*2) glcolor(white) nogextend) ///
	plotregion(lc(black)) ///
	xline(0, lc(red) lp(dash)) ///
	legend(order(3 "Controls" 6 "No Controls") pos(6) row(1))	
	
	gr export "Figures/Appendix C/Figure_C8.png", width(4000) replace
	
}	


	
	

	
********************************************************************************
*** FIGURE C.9
********************************************************************************

// By attack

cap drop s_attacks_* 

foreach y in dista_labcon_d {

	bys wave attack_id: egen p_c=sd(post) if `y'!=.
	gen s_attacks_`y'=(p_c>0 & p_c!=.)
	drop p_c

	est clear
	
	*ALL ATTACKS
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' , absorb(oslauawave, save) vce(cluster oslaua)
		loc beta=_b[post]

	*FAR-RIGHT
	capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n1=e(N)
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)

	*ISLAMIC
	capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n2=e(N)
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)

	coefplot ///
	(est2, offset(0.2)  keep(post) rename(post = "Far-right Attacks") msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est3, offset(-0.2) keep(post) rename(post = "Far-right Attacks") msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est4, offset(0.2)  keep(post) rename(post = "Islamic Attacks") msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est5, offset(-0.2) keep(post) rename(post = "Islamic Attacks") msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	, levels(95 90) ///
	xtitle("Coefficient of 'Post-attack'") ///
	groups("Far-right Attacks" = "N = `n1'" "Islamic Attacks" = "N = `n2'") ///
	yscale(alt axis(2)) ///
	xlabel(-0.1(0.025)0.1) ///
	grid(between glpattern(dash) glwidth(*2) glcolor(white) nogextend) ///
	plotregion(lc(black)) ///
	xline(0, lc(red) lp(dash)) ///
	yline(6, lc(gs12%60) lp(solid) lw(medthick)) ///
	legend(order(3 "Controls" 6 "No Controls") pos(6) row(1))
	
	gr export "Figures/Appendix C/Figure_C9.png", width(4000) replace

	}	

	
	

	
********************************************************************************
*** TABLE C.10
********************************************************************************

cap drop s_attacks_*

*keep respondents from waves/attacks where the question under scrutiny was asked
bys wave attack_id: egen post_sd=sd(post) if dista_labcon!=.
gen s_attacks_dista_labcon=(post_sd>0 & post_sd!=.)
drop post_sd

* Age, gender, education and religion
est clear
forv i=2/3 {

	eststo: reghdfe dista_labcon i.age_dummy##i.post female i.work_clean i.education_clean i.marital_clean i.children_clean i.ethnicity_clean i.religion_clean if s_attacks_dista_labcon & gname_small==`i', absorb(oslauawave) vce(cluster oslaua)
	estadd loc oslauawave "Yes", replace							
	estadd loc controls "Yes", replace
	
	eststo: reghdfe dista_labcon i.female##i.post age age2 i.work_clean i.education_clean i.marital_clean i.children_clean i.ethnicity_clean i.religion_clean if s_attacks_dista_labcon & gname_small==`i', absorb(oslauawave) vce(cluster oslaua)
	estadd loc oslauawave "Yes", replace							
	estadd loc controls "Yes", replace
	
	eststo: reghdfe dista_labcon i.education_dummy##i.post age age2 female i.work_clean i.marital_clean i.children_clean i.ethnicity_clean i.religion_clean if s_attacks_dista_labcon & gname_small==`i', absorb(oslauawave) vce(cluster oslaua)
	estadd loc oslauawave "Yes", replace							
	estadd loc controls "Yes", replace
	
	eststo: reghdfe dista_labcon i.religion_out##i.post age age2 female i.work_clean i.education_clean i.marital_clean i.children_clean i.ethnicity_clean if s_attacks_dista_labcon & gname_small==`i', absorb(oslauawave) vce(cluster oslaua)
	estadd loc oslauawave "Yes", replace							
	estadd loc controls "Yes", replace

}
		
esttab est* using "Tables/Appendix C/Table_C10", star(* .1 ** .05 *** .01) se b(3) r2 ///
keep(1.post 1.*#1.post) ///
order(1.post 1.*#1.post) ///
varl(1.post "Post-attack" 1.age_dummy#1.post "Post-attack $\times$ Older" 1.female#1.post "Post-attack $\times$ Female" 1.education_dummy#1.post "Post-attack $\times$ High education" 1.religion_out#1.post "Post-attack $\times$ Out-group religion") ///
s(oslauawave controls N_clust r2 N, ///
label("LAD $\times$ Wave FEs" "Controls" "No. of LADs" "R-squared" "Observations") ///
fmt(3 3 %9.0f 3 %9.0f)) ///
replace html nonotes	



	
********************************************************************************
*** FIGURE C.11
********************************************************************************

cap drop s_attacks_* 

est clear

foreach y in mii_austerity mii_economy mii_environment mii_immigration {

	*keep respondents from waves/attacks where the question under scrutiny was asked
	bys wave attack_id: egen p_c=sd(post) if `y'!=.
	gen s_attacks_`y'=(p_c>0 & p_c!=.)
	drop p_c

	*FAR-RIGHT
	*controls
	capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n1_`y'=e(N)
	*no controls
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)

	*ISLAMIC
	*controls
	capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n2_`y'=e(N)
	*no controls
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)

	}
	
	coefplot ///
	(est1, offset(0.2)   keep(post) rename(post = "Austerity (Far-right)") label(2 days) msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est2, offset(-0.2)  keep(post) rename(post = "Austerity (Far-right)") label(3 days) msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est3, offset(0.2)   keep(post) rename(post = "Austerity (Islamic)") label(2 days) msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est4, offset(-0.2)  keep(post) rename(post = "Austerity (Islamic)") label(3 days) msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est5, offset(0.2)   keep(post) rename(post = "Economy (Far-right)") label(2 days) msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est6, offset(-0.2)  keep(post) rename(post = "Economy (Far-right)") label(3 days) msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est7, offset(0.2)   keep(post) rename(post = "Economy (Islamic)") label(2 days) msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est8, offset(-0.2)  keep(post) rename(post = "Economy (Islamic)") label(3 days) msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est9, offset(0.2)   keep(post) rename(post = "Environment (Far-right)") label(2 days) msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est10, offset(-0.2) keep(post) rename(post = "Environment (Far-right)") label(3 days) msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est11, offset(0.2)  keep(post) rename(post = "Environment (Islamic)") label(2 days) msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est12, offset(-0.2) keep(post) rename(post = "Environment (Islamic)") label(3 days) msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est13, offset(0.2)  keep(post) rename(post = "Immigration (Far-right)") label(2 days) msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est14, offset(-0.2) keep(post) rename(post = "Immigration (Far-right)") label(3 days) msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est15, offset(0.2)  keep(post) rename(post = "Immigration (Islamic)") label(2 days) msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est16, offset(-0.2) keep(post) rename(post = "Immigration (Islamic)") label(3 days) msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	, levels(95 90) ///
	xtitle("Coefficient of 'Post-attack'") ///
	groups("Austerity (Far-right)" = "N = `n1_mii_austerity'" "Austerity (Islamic)" = "N = `n2_mii_austerity'" "Economy (Far-right)" = "N = `n1_mii_economy'" "Economy (Islamic)" = "N = `n2_mii_economy'" "Environment (Far-right)" = "N = `n1_mii_environment'" "Environment (Islamic)" = "N = `n2_mii_environment'" "Immigration (Far-right)" = "N = `n1_mii_immigration'" "Immigration (Islamic)" = "N = `n2_mii_immigration'" ) ///
	yscale(alt axis(2)) ///
	xlabel(-0.05(0.05)0.3) ///
	grid(between glpattern(dash) glwidth(*2) glcolor(white) nogextend) ///
	plotregion(lc(black)) ///
	xline(0, lc(red) lp(dash)) ///
	yline(4 8 12, lc(gs12%60) lp(solid) lw(medthick)) ///
	legend(order(3 "Controls" 6 "No Controls") pos(6) row(1))

	gr export "Figures/Appendix C/Figure_C11.png", width(4000) replace




********************************************************************************
*** TABLE C.12
********************************************************************************

***Note the imputed partisanship is computed before 

cap drop s_attacks_*

qui { // TABLE
	
* Panel A
est clear
foreach yyy in immigcultural immigecon {
	
	foreach ppp in "con" "lab" "greenlib" {
			
		*keep respondents from waves/attacks where the question under scrutiny was asked
		cap drop s_attacks_*
		bys wave attack_id: egen p_c=sd(post) if `yyy'!=.
		gen s_attacks_`yyy'=(p_c>0 & p_c!=.)
		drop p_c
		
		di "`yyy' - `i' - `ppp'"
		eststo: reghdfe `yyy' post $controls if s_attacks_`yyy' & gname_small==2 & lag_partyid_imp_`ppp'==1, absorb(oslauawave) vce(cluster oslaua)
		estadd loc oslauawave "Yes"
		estadd loc controls "Yes"
		estadd loc partisan "`ppp'"
		
	} 

}
		
esttab est* using "Tables/Appendix C/Table_C12", star(* .1 ** .05 *** .01) se b(3) r2 ///
keep(post) ///
order(post) ///
varl(post "Post-attack") ///
s(partisan oslauawave controls N_clust r2 N, ///
label("Partisan identity" "LAD $\times$ Wave FEs" "Controls" "No. of LADs" "R-squared" "Observations") ///
fmt(3 3 3 %9.0f 3 %9.0f)) ///
replace html nonotes	

* Panel B
est clear
forv i=2/3 {
	
	foreach ppp in "con" "lab" "greenlib" {
		
		*keep respondents from waves/attacks where the question under scrutiny was asked
		cap drop s_attacks_*
		bys wave attack_id: egen p_c=sd(post) if likeukip!=.
		gen s_attacks_likeukip=(p_c>0 & p_c!=.)
		drop p_c
		
		eststo: reghdfe likeukip post $controls if s_attacks_likeukip & gname_small==`i' & lag_partyid_imp_`ppp'==1, absorb(oslauawave) vce(cluster oslaua)
		estadd loc oslauawave "Yes"
		estadd loc controls "Yes"
		estadd loc partisan "`ppp'"
		
	}
}

esttab est* using "Tables/Appendix C/Table_C12", star(* .1 ** .05 *** .01) se b(3) r2 ///
keep(post) ///
order(post) ///
varl(post "Post-attack") ///
s(partisan oslauawave controls N_clust r2 N, ///
label("Partisan identity" "LAD $\times$ Wave FEs" "Controls" "No. of LADs" "R-squared" "Observations") ///
fmt(3 3 3 %9.0f 3 %9.0f)) ///
append html nonotes	


}






********************************************************************************
*** FIGURE C.13a
********************************************************************************
/*
preserve 

// Prime Minister topics

*open the dataset
import delimited "tweets_pm.csv", clear 

*distinguish attack types
g type="Far-right" if attack=="Jo Cox" | attack=="Finsbury Park"
replace type="Islamic" if type==""

*collapse by attack and whether in the 3days pre-post attack
collapse (mean) sent_trust=trust (semean) se_trust=trust, by(type post)

reshape long sent_ se_, i(type post) j(sentiment) string

*rename sentiments
replace sentiment="Trust" if sentiment=="trust"

*standard errors
g se_up=sent_+se_*1.65 // 10%
g se_lo=sent_-se_*1.65 // 10%

loc i=1
foreach type in "Far-right" "Islamic" { 

g gr_pos=.
replace gr_pos=0.5 if type=="`type'" & sentiment=="Trust" & post=="Pre-attack"
replace gr_pos=1.5 if type=="`type'" & sentiment=="Trust" & post=="Post-attack"

twoway ///
(bar sent_ gr_pos if post=="Pre-attack" & type=="`type'", fcolor(blue%30) color(blue)) ///
(bar sent_ gr_pos if post=="Post-attack" & type=="`type'", fcolor(red%50) color(red)) ///
(rcap se_up se_lo gr_pos, lc(black)) ///
, xlabel(1 "Trust") ///
yscale(range(0 0.18)) ylabel(0 0.045 0.09 0.135 0.18) ///
ytitle("") xtitle("") title("`type' Attacks") ///
plotregion(lc(black)) ylabe(, nogrid) ///
legend(order(1 "Pre-attack" 2 "Post-attack") pos(6) row(1)) ///
name("gr_`i'", replace)

drop gr_pos

loc i=`i'+1

}

grc1leg gr_1 gr_2, ring(4) b1("Sentiment") l1("Mean value")
gr export "Figures/Appendix C/Figure_C13a.png", width(4000) replace

restore 
*/



********************************************************************************
*** FIGURE C.13b
********************************************************************************

cap drop s_attacks_* 

est clear 

foreach y in like_pm {

	*keep respondents from waves/attacks where the question under scrutiny was asked
	bys wave attack_id: egen p_c=sd(post) if `y'!=.
	gen s_attacks_`y'=(p_c>0 & p_c!=.)
	drop p_c

	*FAR-RIGHT
	*controls
	capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n1_`y'=e(N)
	*no controls
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)

	*ISLAMIC
	*controls
	capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n2_`y'=e(N)
	*no controls
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)


	coefplot ///
	(est1, offset(0.2)  keep(post) rename(post = "Far-right Attacks") label(2 days) msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est2, offset(-0.2) keep(post) rename(post = "Far-right Attacks") label(3 days) msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est3, offset(0.2)  keep(post) rename(post = "Islamic Attacks") label(2 days) msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est4, offset(-0.2) keep(post) rename(post = "Islamic Attacks") label(3 days) msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	, levels(95 90) ///
	xtitle("Coefficient of 'Post-attack'") ///
	groups("Far-right Attacks" = "N = `n1_`y''" "Islamic Attacks" = "N = `n2_`y''") ///
	xlabel(-0.4(0.2)0.4) ///
	yscale(alt axis(2)) ///
	grid(between glpattern(dash) glwidth(*2) glcolor(white) nogextend) ///
	plotregion(lc(black)) ///
	xline(0, lc(red) lp(dash)) ///
	legend(order(3 "Controls" 6 "No Controls") pos(6) row(1))	
	
	gr export "Figures/Appendix C/Figure_C13b.png", width(4000) replace
	
}
